﻿package 
{
	import fl.transitions.*;
	import fl.transitions.easing.*;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * 
	 */
	public class Prototipo extends MovieClip
	{
		var mover:Tween; 
		var mover2:Tween ;
		public function Escenario()
		{
			pararMuneco();
			
			
			stage.addEventListener( MouseEvent.CLICK, clicOnArea);
		}
		
		private function termino (e:TweenEvent){
			pararMuneco();
		}

		private function clicOnArea(e:MouseEvent):void 
		{
			
			select.x = mouseX - select.width/2
			select.y = mouseY - select.height/2
			munecoMc.rotation = (180*Math.atan2(mouseY-munecoMc.y,mouseX-munecoMc.x))/Math.PI + 90;

			if ( mover != null )
				mover.removeEventListener(TweenEvent.MOTION_FINISH, termino);
				
			var dXY:Number = Math.sqrt(Math.pow(mouseX - munecoMc.x, 2) + Math.pow(mouseY - munecoMc.y, 2));

			var time:Number = dXY / 100;
			mover = new Tween(munecoMc, "x", null, munecoMc.x, mouseX,time,true);
			mover2 = new Tween(munecoMc, "y", null, munecoMc.y, mouseY, time, true);
			
			
			
			mover.start();
			mover2.start();
			
			munecoMc.play();
			
			mover.addEventListener(TweenEvent.MOTION_FINISH, termino);
		}
		
		private function pararMuneco():void
		{
			munecoMc.gotoAndStop(1);
		}
		
	}
}